chore(copilot): use GH_HOST for Copilot endpoints and token lookup#2705
chore(copilot): use GH_HOST for Copilot endpoints and token lookup#2705AmadeusK525 wants to merge 1 commit intoolimorris:mainfrom
Conversation
|
I think it would be cleaner and better in the long run to have these URLs stored in the |
|
This PR is stale because it has been open for 30 days with no activity. |
|
@olimorris I agree, although I really don't have the time to tackle this task. But I mean, this at least works for now, without this workaround it doesn't (from my tests), but I guess It's okay if you don't want to merge this, it doesn't seem like this feature has too much demand :) |
|
@AmadeusK525 this is still a valid PR imo and something the community would benefit from. Appreciate you're time constrained however this could be given to an LLM to finish off. My only ask was that users have a way of overwriting the base and token URLs in their config. |
Update Copilot HTTP requests and token lookup to respect the `GH_HOST` env var, allowing use with GitHub Enterprise instances. Some networks block the `github.com` endpoints, so they won't work at all. Provide a way for the user to hit different endpoint other than `github.com` (e.g. mycorp.ghe.com) without patching the source code. The `GH_HOST` environment variable is the same one used to override this for `gh` cli: https://cli.github.com/manual/gh_help_environment
cf561f3 to
94e6024
Compare
|
Huge thanks to @AmadeusK525 |
|
Today I took some time with Copilot and worked out a solution for this issues. I introduced a github_enterprise_url to copilot.env. I would like to open a PR for this. How can I do this? |
| endpoint = "https://api.github.com/copilot_internal/v2/token" | ||
| else | ||
| -- GitHub Enterprise usually puts the API under /api/v3 | ||
| endpoint = string.format("https://%s/api/v3/copilot_internal/v2/token", host) |
There was a problem hiding this comment.
| endpoint = string.format("https://%s/api/v3/copilot_internal/v2/token", host) | |
| endpoint = string.format("https://%s/api/v3/copilot_internal/user", host) |
| local host = vim.env.GH_HOST or "github.com" | ||
| local endpoint | ||
| if host == "github.com" then | ||
| endpoint = "https://api.github.com/copilot_internal/v2/token" |
There was a problem hiding this comment.
| endpoint = "https://api.github.com/copilot_internal/v2/token" | |
| endpoint = "https://api.github.com/copilot_internal/user" |
this seems to be a copy paste error, the path was "/copilot_internal/user" not "*/token" it's for stats not to request a token.
| local current_url = adapter.url or "https://api.githubcopilot.com/chat/completions" | ||
| local base_url = current_url:gsub("/chat/completions$", ""):gsub("/responses$", "") |
There was a problem hiding this comment.
do I miss something here or is this basically enough if we expect base url in adapter.url
| local current_url = adapter.url or "https://api.githubcopilot.com/chat/completions" | |
| local base_url = current_url:gsub("/chat/completions$", ""):gsub("/responses$", "") | |
| local base_url = adapter.url or "https://api.githubcopilot.com" |
| text = true, | ||
| tokens = true, | ||
| }, | ||
| url = "https://api.githubcopilot.com/chat/completions", |
There was a problem hiding this comment.
| url = "https://api.githubcopilot.com", |
|
Was so free to add some suggestions, feel free to ignore them. This is something I am looking forward to be merged, thank you for the work :) |
This PR is a continuation of #2090, but with a complete "fix" for the GH_HOST issue. There are several places where the variable needs to be read-referenced, and as I said there I don't think this fix is actually good, but it does work (I've been using my fork for a couple of months).